/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：GameData.java <br>
 * 创建时间：2013-5-20 下午4:52:08 <br>
 * 所属项目：GmudEX <br>
 *
 * @author 12548 <br>
 */
package lostland.gmud.exv2.data;

import android.util.SparseBooleanArray;
import android.util.SparseIntArray;

import java.io.Serializable;
import java.util.ArrayList;

import lostland.gmud.exv2.Direction;
import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.GameConstants;
import lostland.gmud.exv2.Gmud;

/**
 * 类名：GameData <br>
 * 说明：游戏主数据，本类成员均会写入存档
 *
 * @author 12548
 */
public class GameData implements Serializable {

	private static final long serialVersionUID = -363370501189352219L;

	/**
	 * 类名：GameStory <br>
	 * 说明：考虑要加入剧情处理，当剧情变化之后对游戏世界产生影响，每次启动游戏都要调用的世界变化。 <br>
	 * 尽量使用简单剧情以提升效率。
	 *
	 * @author 12548
	 */
	public static final class GameStory {

		public static final int SIMPLESTORY_MARRIAGE = 0; // 结婚
		public static final int SWITCHSTORY_TUTU = 0; // 凸凸秘籍任务
		public static final int MULTISTATESTORY_PAY = 0; // 作者乞讨

		/**
		 * 进行简单剧情变化处理。
		 *
		 * @param storyid 要处理的剧情编号
		 */
		private static void doSimpleStory(int storyid) {
			switch (storyid) {
				case SIMPLESTORY_MARRIAGE:
					if (Game.getData().spouse != null) {
						new Room().npc(Game.getData().spouse)
								.say("亲爱的，你慢慢飞~")
								.flag(Npc.FLAG_SPOUSE)
								.flag(Npc.FLAG_NODROP)
								.flag(Npc.FLAG_IMPORTANT)
								.look(-1, -1)
								.introduction("")
								.place(GameConstants.SPOUSE_PLACE);
					}
					break;
			}
		}

		private void doSwitchStory(int storyid) {
// final boolean state = switch_story_state.get(storyid);
			switch (storyid) {
// case SWITCHSTORY_TUTU: {
// if (!state) {
// Room r = new Room();
// r.map(47).setEvent(21, 4, -1);
// r.map(47).setWalkable(21, 4, GmudMap.MP_WALKABLE); //凸凸
// if (GmudGame.getData().getSyuume() > 0)
// r.map(0).npc(2, 2, Room.vip_npc[1]);
// }
// }
// break;
			}
		}

		private void doMultistateStory(int storyid) {

		}

		private SparseBooleanArray simple_story_state = new SparseBooleanArray();
		private SparseBooleanArray switch_story_state = new SparseBooleanArray();
		private SparseIntArray multistate_story_state = new SparseIntArray();


		public void setSwitchStory(int storyid, boolean value) {
			switch_story_state.put(storyid, value);
			doSwitchStory(storyid);
		}

		public boolean getSwitchStoryState(int storyid) {
			return switch_story_state.get(storyid);
		}

		public void setMultistateStory(int storyid, int value) {
			multistate_story_state.put(storyid, value);
			doMultistateStory(storyid);
		}

		public int getMultistateStoryState(int storyid) {
			return multistate_story_state.get(storyid);
		}


		/**
		 * 通过指定简单剧情。
		 *
		 * @param storyid 剧情编号
		 */
		public void passSimpleStory(int storyid) {
			simple_story_state.put(storyid, true);
			doSimpleStory(storyid);
		}

		/**
		 * 检查指定简单剧情是否已通过。
		 *
		 * @param storyid 剧情编号
		 * @return 如果该剧情已通过，则返回true。
		 */
		public boolean getSimpleStoryState(int storyid) {
			return simple_story_state.get(storyid);
		}
	}

	public GameStory story = new GameStory();

	public ArrayList<Integer> death_note, vanish_note;
	public boolean hasstone[] = {true, true, true, true, true, true};

	public int game_difficulty = 1;

	public boolean challenge_won = false; // unused

	public boolean tournament_finished = true;

	private int syuume = 0; // 周目

	public MainChar chest = new MainChar();

	public boolean getinChest(Item item) {
		boolean flag = chest.give(item);
		if (flag) {
			Gmud.mc.drop(item);
		}
		return flag;
	}

	public boolean getoutChest(Item item) {
		boolean flag = Gmud.mc.give(item);
		if (flag) {
			chest.drop(item);
		}
		return flag;
	}


	public int dancing_best = 1000;
	public int q2048_best = 10;
	public int gold_medal = 0;

	public boolean task_stone = false;
	public boolean task_smr_not_done = true;
	public boolean task_lry_not_done = true;

	public double stat_time = 0;

	public int yellowcal = 0;

	public int stat_defeated_by_tutu = 0;
	public int stat_kills = 0;
	public int stat_hunts = 0;
	public int stat_asss = 0;
	public int stat_feeds = 0;
	public int stat_wins = 0;
	public int stat_start = 0;
	public static final int MENTION_WINS = 1;

	public float hour = 0, hungerTime = 0, stoneTime = 0;

	public boolean auto_save = false; // @todo 自动存档

	public int getSyuume() {
		return syuume;
	}

	public void setSyuume(int value) {
		syuume = value;
	}

	public GameData() {
		death_note = new ArrayList<>();
		vanish_note = new ArrayList<>();
		fp = new ArrayList<>();
	}

	public ArrayList<FlyPoint> fp;

	public boolean mdone = false;
	public MainChar spouse = null; // 配偶
	public String spouseid = ""; // 配偶的绑定角色objectID

	public int DuchangTaskCooldownDay = 0;


	public int mpp = 0; // 老婆婆任务状态

	public void addfp(int map, int x, int y, Direction d) {

		for (FlyPoint i : fp) {
			if (i.map == map)
				return;
		}
		if (Gmud.maps[map].extraInfo.AutoAddFlyPoint) {
			fp.add(new FlyPoint(map, x, y, d));
		}
	}

	public void addfp2(int map, int x, int y, Direction d) {
		fp.add(new FlyPoint(map, x, y, d));
	}

	public SparseBooleanArray game_switch = new SparseBooleanArray();
	public SparseIntArray game_variavble = new SparseIntArray();

	public void init() {
		for (int i = 0; i < story.switch_story_state.size(); i++) {
			story.doSwitchStory(story.switch_story_state.keyAt(i));
		}

		for (int i = 0; i < story.simple_story_state.size(); i++) {
			if (story.simple_story_state.valueAt(i)) {
				GameStory.doSimpleStory(story.simple_story_state.keyAt(i));
			}
		}

		for (int i = 0; i < story.multistate_story_state.size(); i++) {
			story.doMultistateStory(story.multistate_story_state.keyAt(i));
		}
	}
}
